import logging
import logging.handlers

def get_logger(name, filename = '', format = '%(levelname)-8s %(name)s %(lineno)d %(threadName)s %(message)s', level = logging.DEBUG, default = False):
    logger = logging.getLogger(name)
    
    if filename:
        handler = logging.handlers.RotatingFileHandler(filename)
        handler.setFormatter(logging.Formatter(format))
        if default:
            logging.root.addHandler(handler)
        else:
            logger.addHandler(handler)
        
    if default:
        logging.root.setLevel(level)
    else:
        logger.setLevel(level)
    return logger
